// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SqlAzureLocation.cs" company="">
//   
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExecutionTool.Profile
{
    using System.Runtime.Serialization;

    using ExecutionTool.Common;

    [DataContract]
    public class SqlAzureLocation
    {
        #region Constants

        public const string SqlAzureServerNameTemplate = "{0}.database.windows.net";

        #endregion

        #region Fields

        private string decryptedPassword;

        #endregion

        #region Public Properties

        [DataMember]
        public string DatabaseName { get; set; }

        [DataMember]
        public string Description { get; set; }

        [DataMember]
        public string EncryptedPassword { get; set; }

        public string Password
        {
            get
            {
                if (string.IsNullOrWhiteSpace(this.decryptedPassword))
                {
                    this.decryptedPassword = Helper.Decrypt(this.EncryptedPassword);
                }

                return this.decryptedPassword;
            }

            set
            {
                this.EncryptedPassword = Helper.Encrypt(value);
            }
        }

        public string ServerName
        {
            get
            {
                return string.Format(SqlAzureServerNameTemplate, this.ServerNamePrefix);
            }
        }

        [DataMember]
        public string ServerNamePrefix { get; set; }

        [DataMember]
        public string UserName { get; set; }

        #endregion
    }
}
